#include "component/Event.h"

using namespace eats_core;

Event::Event()
{
    //ctor
}

Event::~Event()
{
    //dtor
}

void Event::onEvent(SDL_Event* Event)
{
    switch(Event->type) {
        case SDL_ACTIVEEVENT: {
            switch(Event->active.state) {
                case SDL_APPMOUSEFOCUS: {
                    if ( Event->active.gain )    mouseFocusEvent();
                    else                mouseBlurEvent();

                    break;
                }
                case SDL_APPINPUTFOCUS: {
                    if ( Event->active.gain )    inputFocusEvent();
                    else                inputBlurEvent();

                    break;
                }
                case SDL_APPACTIVE:    {
                    if ( Event->active.gain )
                        restoreEvent();
                    else
                        minimizeEvent();
                    break;
                }
            }
            break;
        }

        case SDL_KEYDOWN: {
            keyDownEvent(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
            break;
        }

        case SDL_KEYUP: {
            keyUpEvent(Event->key.keysym.sym,Event->key.keysym.mod,Event->key.keysym.unicode);
            break;
        }

        case SDL_MOUSEMOTION: {
            mouseMoveEvent(Event->motion.x,Event->motion.y,Event->motion.xrel,Event->motion.yrel,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,(Event->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0);
            break;
        }

        case SDL_MOUSEBUTTONDOWN: {
            switch(Event->button.button) {
                case SDL_BUTTON_LEFT: {
                    lButtonDownEvent(Event->button.x,Event->button.y);
                    break;
                }
                case SDL_BUTTON_RIGHT: {
                    rButtonDownEvent(Event->button.x,Event->button.y);
                    break;
                }
                case SDL_BUTTON_MIDDLE: {
                    mButtonDownEvent(Event->button.x,Event->button.y);
                    break;
                }
            }
            break;
        }

        case SDL_MOUSEBUTTONUP:    {
            switch(Event->button.button) {
                case SDL_BUTTON_LEFT: {
                    lButtonUpEvent(Event->button.x,Event->button.y);
                    break;
                }
                case SDL_BUTTON_RIGHT: {
                    rButtonUpEvent(Event->button.x,Event->button.y);
                    break;
                }
                case SDL_BUTTON_MIDDLE: {
                    mButtonUpEvent(Event->button.x,Event->button.y);
                    break;
                }
            }
            break;
        }

        case SDL_JOYAXISMOTION: {
            joyAxisEvent(Event->jaxis.which,Event->jaxis.axis,Event->jaxis.value);
            break;
        }

        case SDL_JOYBALLMOTION: {
            joyBallEvent(Event->jball.which,Event->jball.ball,Event->jball.xrel,Event->jball.yrel);
            break;
        }

        case SDL_JOYHATMOTION: {
            joyHatEvent(Event->jhat.which,Event->jhat.hat,Event->jhat.value);
            break;
        }
        case SDL_JOYBUTTONDOWN: {
            joyButtonDownEvent(Event->jbutton.which,Event->jbutton.button);
            break;
        }

        case SDL_JOYBUTTONUP: {
            joyButtonUpEvent(Event->jbutton.which,Event->jbutton.button);
            break;
        }

        case SDL_QUIT: {
            exitEvent();
            break;
        }

        case SDL_SYSWMEVENT: {
            //Ignore
            break;
        }

        case SDL_VIDEORESIZE: {
            resizeEvent(Event->resize.w,Event->resize.h);
            break;
        }

        case SDL_VIDEOEXPOSE: {
            exposeEvent();
            break;
        }

        default: {
            userEvent(Event->user.type,Event->user.code,Event->user.data1,Event->user.data2);
            break;
        }
    }
}

void Event::inputFocusEvent()
{

}

void Event::inputBlurEvent()
{

}

void Event::keyDownEvent(SDLKey sym, SDLMod mod, Uint16 unicode)
{

}

void Event::keyUpEvent(SDLKey sym, SDLMod mod, Uint16 unicode)
{

}

void Event::mouseFocusEvent()
{

}

void Event::mouseBlurEvent()
{

}

void Event::mouseMoveEvent(int mX, int mY, int relX, int relY, bool Left,bool Right,bool Middle)
{

}

void Event::mouseWheelEvent(bool Up, bool Down)
{

}

void Event::lButtonDownEvent(int mX, int mY)
{

}

void Event::lButtonUpEvent(int mX, int mY)
{

}

void Event::rButtonDownEvent(int mX, int mY)
{

}

void Event::rButtonUpEvent(int mX, int mY)
{

}

void Event::mButtonDownEvent(int mX, int mY)
{

}

void Event::mButtonUpEvent(int mX, int mY)
{

}

void Event::joyAxisEvent(Uint8 which, Uint8 axis, Sint16 value)
{

}

void Event::joyButtonDownEvent(Uint8 which, Uint8 button)
{

}

void Event::joyButtonUpEvent(Uint8 which, Uint8 button)
{

}

void Event::joyHatEvent(Uint8 which, Uint8 hat, Uint8 value)
{

}

void Event::joyBallEvent(Uint8 which, Uint8 ball, Sint16 xrel, Sint16 yrel)
{

}

void Event::minimizeEvent()
{

}

void Event::restoreEvent()
{

}

void Event::resizeEvent(int w,int h)
{

}

void Event::exposeEvent()
{

}

void Event::exitEvent()
{

}

void Event::userEvent(Uint8 type, int code, void* data1, void* data2)
{

}

